package com.share.common.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author syq
 * @data 2019/8/1
 */
public class UUIDUtil {
    private static String baseNum = "0123456789";
    private static String baseAlph = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    private static String baseStr = baseNum + baseAlph;

    public static String genUUId() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replaceAll("-", "");
    }

    public static String getDateTimeStr() {
        return DateExtUtil.getDateTime();
    }

    /*文件名*/
    public static String genFileName() {
        UUID uuid = UUID.randomUUID();
        String format = DateExtUtil.getDateTime();
        return format + "-" + genRandomString(6);
    }

    private static Random rand = new Random();

    /*生产  数字 =随机数*/
    public static String genRandomNumber(int lenth) {
        int baseLenth = baseNum.length();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < lenth; i++) {
            sb.append(baseNum.charAt(rand.nextInt(baseLenth)));
        }
        return sb.toString();
    }

    /*生产 一个 数字 [0-max)的区间 */
    public static Integer genRandomInt(int max) {
        return rand.nextInt(max);
    }

    /*生产纯 字母+数字=随机数*/
    public static String genRandomString(int lenth) {
        int baseLenth = baseStr.length();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < lenth; i++) {
            sb.append(baseNum.charAt(rand.nextInt(baseLenth)));
        }
        return sb.toString();
    }

}
